﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using KVB.Common;

namespace Customer_Profile.Admin
{
    public partial class TypeModify : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["id"] != null)
                {
                    try
                    {
                        CodeTypeDao typdao = new CodeTypeDao();
                        DataSet ds = typdao.GetModel(Request.QueryString["id"]);
                        if (ds != null && ds.Tables.Count > 0)
                        {
                            txtName.Value = ds.Tables[0].Rows[0]["CodeTypeName"].ToString();
                            txtRemark.Value = ds.Tables[0].Rows[0]["CodeTypeRemark"].ToString();
                            txtOrderid.Value = ds.Tables[0].Rows[0]["CodeTypeOrder"].ToString();
                            drpUsed.Items.FindByValue(ds.Tables[0].Rows[0]["Y_N"].ToString()).Selected = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.WriteDefaultLog("TypeModifyPage_Load", ex.ToString());
                    }
                }
                else
                {
                    Comm.ViewMsgGoUrl("CodeModify.aspx", "not exist");
                }
            }
        }

        protected void ibtnModify_ServerClick(object sender, EventArgs e)
        {
            if (Request.QueryString["id"] != null)
            {
                try
                {
                    string id = Request.QueryString["id"].ToString();
                    CodeTypeDao codeTypeDao = new CodeTypeDao();
                    codeTypeDao.Modify(id, txtName.Value.Trim(), txtRemark.Value.Trim(), txtOrderid.Value.Trim(), drpUsed.SelectedValue.ToString().Trim());
                    Comm.ViewAlertMsg("Succeed");
                }
                catch (Exception ex)
                {
                    Log.WriteDefaultLog("TypeModifyibtnModify_ServerClick", ex.ToString());
                }
            }
        }

        protected void ibtnBack_ServerClick(object sender, EventArgs e)
        {
            Response.Redirect("CodeManage.aspx");
        }
    }
}
